<?php
/*
 * 车系的API访问
 * @package    auto
 * @author     Mark
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version    $Id: fbdcdf2250cb7cbe24d1f3008f179c7161121d57 $
 */
require_once '../../common.inc.php';
header("content-type: application/x-javascript"); //设置头，否则chrome会失败
switch ($action) {
	case 'autoRankTree':
		if (!isset($pid)) {
			$pid = 0;
		} else {
			$pid = intval($pid);
		}
		echo json_encode(AutoCategory::easyuiTree($pid));
		break;
	case 'autoBrands':
		$adfts  = explode(',', $aDft);
		$brands = AutoRank::getBrands(array('arid' => 'brandId', 'name' => 'brandName'), $adfts);
		echo json_encode($brands);
		break;
	case 'autoCars':
		$abids = explode(',', $aBid);
		$adfts = explode(',', $aDft);
		$cars  = AutoRank::getCars(array('arid' => 'carId', 'name' => 'carName'), $abids, $adfts);
		echo json_encode($cars);
		break;
	case 'autoModels':
		$acids  = Filter::vInts($aCid);
		$models = AutoRank::getModels(array('amid' => 'modelId', 'name' => 'modelName'), $acids);
		echo json_encode($models);
		break;
	case 'autoPicture':
		$carId        = isset($aCid) ? intval($aCid) : 0;
		$modelId      = isset($aMid) ? intval($aMid) : 0;
		$pictureId    = isset($aPid) ? intval($aPid) : 0;
		$pictureCatId = isset($aLid) ? intval($aLid) : 0;
		$pics = AutoPicture::getPicturesAPI($carId, $modelId, $pictureId, $pictureCatId);
		echo sprintf('%s(%s);', $_GET['callback'], json_encode($pics));
		break;
	case 'autoCompare':
		$compare = AutoCompare::getCompareAPI($autoIds, $autoType);
		echo sprintf('%s(%s);', $_GET['callback'], json_encode($compare));
		break;
}
